package service;

import dao.UserDao;
import entity.User;
import util.StringUtils;

public class UserService {
    private UserDao ud = new UserDao();

    public User login(String username,String password){
        User u = ud.findByName(username);
        if(u !=null){
            if(password.equals(u.getPassword())){
                return u;
            }
        }
        return null;
    }
    public User findById(String id){
        int uid = 0;
        if(StringUtils.isNotNull(id)){
            uid = Integer.parseInt(id);
        }
        return ud.findById(uid);
    }
    public int update(String username,String name,String gender,String permission,String remark,String id){
        if(StringUtils.isNotNull(username)
                &&StringUtils.isNotNull(name)
                &&StringUtils.isNotNull(gender)
                &&StringUtils.isNotNull(permission)
                &&StringUtils.isNotNull(remark)
                &&StringUtils.isNotNull(id)){
            User u = new User();
            u.setUsername(username);
            u.setName(name);
            u.setGender(gender);
            u.setPermission(Integer.parseInt(permission));
            u.setRemark(remark);
            u.setId(Integer.parseInt(id));
            return ud.update(u);

        }
    return 0;}

}
